package com.heima.controller;

import com.heima.pojo.dto.VmDto;
import com.heima.pojo.dto.VmPageDto;
import com.heima.pojo.vo.VmPageVo;
import com.heima.service.VmService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/api/vm-service/vm")
@Api("设备接口")
public class VmController {

    @Autowired
    private VmService vmService;

    /**
     * 分页查询设备
     */
    @GetMapping("/search")
    @ApiOperation("分页查询设备")
    public VmPageVo pageQuery(VmPageDto dto){
        log.info("dto:{}",dto);
        VmPageVo vmPageVo = vmService.pageQuery(dto);
        return vmPageVo;
    }

    /**
     * 新增设备
     */
    @PostMapping
    public Boolean addVm(@RequestBody VmDto dto){
        log.info("dto:{}",dto);
        vmService.saveVm(dto);
        return true;
    }

    /**
     * 修改售货机点位
     */
    @PutMapping("/{id}/{nodeId}")
    @ApiOperation("修改售货机点位")
    public void updateVmNode(@PathVariable Long id,@PathVariable String nodeId){
        log.info("id:{},nodeId:{}",id,nodeId);
        VmDto vmDto = new VmDto();
        vmDto.setId(id.toString());
        vmDto.setNodeId(Long.parseLong(nodeId));
        vmService.saveVm(vmDto);
    }


}
